package com.carl.controller;

import com.carl.exception.MyException;
import com.carl.mapper.UserMapper;
import com.carl.model.User;
import com.carl.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@Controller
public class IndexController {

    @Autowired
    private UserMapper userMapper ;

    @GetMapping("/")
    public String home() throws MyException {
        log.info("$$$$ ---> lombok ~~ ##");
        return "home";
    }

    @GetMapping("/index")
    public String index() throws MyException {
        log.info("$$$$ ---> index ~~ ##");
        return "index";
    }

    @ResponseBody
    @RequestMapping("/{id}/userInfo")
    public Result userInfoById(@PathVariable("id") Long userId) throws MyException {
        Result result = new Result();
        User user = userMapper.selectById(userId);
        result = result.successResult("@@ userInfo-success", user);
        return result ;
    }


}
